﻿using FairyGUI;

namespace GameFramework.UI.FairyGUI
{
    /// <summary>
    /// FairyGUI 界面组辅助器。
    /// </summary>
    internal sealed class FairyGUIGroupHelper : IUIGroupHelper
    {
        public GComponent GroupRoot { get; private set; }
        
        public void Initialize(string groupName)
        {
            var groot = GRoot.inst;
            GroupRoot = new GComponent();
            GroupRoot.gameObjectName = GroupRoot.displayObject.name = GroupRoot.name = $"Group - {groupName}";
            GroupRoot.size = groot.size;
            GroupRoot.Center(true);
            GroupRoot.AddRelation(groot, RelationType.Size);

            groot.AddChild(GroupRoot);
        }
        
        public void Dispose()
        {
            GroupRoot?.Dispose();
            GroupRoot = null;
        }

        public void SetDepth(int depth)
        {
            GroupRoot.sortingOrder = depth + 1;
        }
    }
}